/**
 * Copyright (C) 2009-2012, KingHool.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses.
 */
package com.kinghool.smodel.test;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import com.kinghool.ebos.commons.utils.Utils;
import com.kinghool.smodel.io.bean.annotation.Array;
import com.kinghool.smodel.io.bean.annotation.Attribute;
import com.kinghool.smodel.io.bean.annotation.Bean;
import com.kinghool.smodel.io.bean.annotation.Child;
import com.kinghool.smodel.io.bean.annotation.Exclude;
import com.kinghool.smodel.io.bean.annotation.Text;

/**
 * 
 * @Author Allen Deng(dengtailin@gmail.com) 
 */
@Bean(name = "order")
public class Order {
	@Attribute
	private String id;
	
	@Attribute(name="order-name")
	private String name;

	@Text(child = "order-date")
	private Timestamp orderDate;
	
	@Child(child="customer")
	private Customer customer;

	@Array(container="order-items", child="order-item")
	private List<Item> items = Utils.newList();
	
	/**
	 * the property of includeAll of Order is true by default
	 * the property will be serialized to a child text with child named 'description' 
	 */
	private String description;

	/**
	 * the property of includeAll of Order is true by default
	 * the property marked with @Exclude will be not serialized
	 */
	@Exclude
	private Timestamp createTime;
	
	public Order() {
		this.createTime = new Timestamp(new Date().getTime());
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Timestamp getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Timestamp orderDate) {
		this.orderDate = orderDate;
	}

	public List<Item> getItems() {
		return items;
	}

	public void setItems(List<Item> items) {
		for (Item item : items) {
			addItem(item);
		}
	}
	
	public void addItem(Item item) {
		item.setOrder(this);
		
		this.items.add(item);
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Timestamp getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}

}
